﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Linq;
using ESB.BAM.DAL;

namespace ESB.BAM.BLogic
{
    /// <summary>
    /// This is a class to wrap the row of orchestration mapping data.
    /// </summary>
    public class EsbTrackingOrchestrationDataStep
    {
        public string OrchestrationName { get; set; }
        public string ShapeName { get; set; }
        public string ActivityName { get; set; }
        public string DataName { get; set; }
        public string DataExtractionXPath { get; set; }

        /// <summary>
        /// Gets the data list.
        /// </summary>
        /// <param name="DALDataSet">The DAL data set.</param>
        /// <returns></returns>
        public static EsbTrackingOrchestrationDataStep[] GetDataList(List<EsbTrackingOrchestrationData> DALDataSet)
        {
            if (DALDataSet == null) return null;
            var callToken = Microsoft.BizTalk.CAT.BestPractices.Framework.Instrumentation.TraceManager.TrackingComponent.TraceIn();
            List<EsbTrackingOrchestrationDataStep> Datalst = new List<EsbTrackingOrchestrationDataStep>();
            EsbTrackingOrchestrationDataStep dstep;
            foreach (EsbTrackingOrchestrationData datarow in DALDataSet)
            {
                dstep = new EsbTrackingOrchestrationDataStep()
                {
                    OrchestrationName = datarow.OrchestrationName,
                    ShapeName = datarow.ShapeName,
                    ActivityName = datarow.ActivityName,
                    DataName = datarow.DataName,
                    DataExtractionXPath = datarow.DataExtractionXPath
                };
                Datalst.Add(dstep);
            }
            Microsoft.BizTalk.CAT.BestPractices.Framework.Instrumentation.TraceManager.TrackingComponent.TraceOut(callToken);
            return Datalst.ToArray();
        }
        /// <summary>
        /// Gets the orchestration data list.
        /// </summary>
        /// <param name="OrchestrationName">Name of the orchestration.</param>
        /// <param name="ShapeName">Name of the shape.</param>
        /// <returns></returns>
        public static EsbTrackingOrchestrationDataStep[] GetOrchestrationDataList(string OrchestrationName, string ShapeName)
        {
            var callToken = Microsoft.BizTalk.CAT.BestPractices.Framework.Instrumentation.TraceManager.TrackingComponent.TraceIn();
            EsbTrackingProfilesDbCache cache = EsbTrackingProfilesDbCache.GetCache();
            List<EsbTrackingOrchestrationData> DALDataList = cache.GetOrchestrationDataList(OrchestrationName, ShapeName);
            Microsoft.BizTalk.CAT.BestPractices.Framework.Instrumentation.TraceManager.TrackingComponent.TraceOut(callToken);
            if (DALDataList == null) return null;
            return EsbTrackingOrchestrationDataStep.GetDataList(DALDataList);
        }
    }
}
